/**
 * Below is a sample adapter for connecting with a webservice.
 */

var myRemoteAdapter={
    server:"http://192.168.10.22/wnsgbl-repo/mobileapp/mobile_api/",
    save:function(obj,callback,foo){
        $.get(this.server+"todo.php?axt=save&data="+encodeURIComponent(JSON.stringify(obj)),
            function(id){
                obj.id=id;
                $(document).trigger(obj.name + ":save", obj);
                if(callback)
                    callback(obj);
            }
        );
    },
    fetch:function(item,callback){
        $.get(BASE_URL+"garagesale_items?id="+encodeURIComponent(item.id),
            function(obj){
                
                obj=JSON.parse(obj);
                if(callback)
                    callback(obj);
            }
        );
    },
    fetchAll:function(id,callback){
        $.get(BASE_URL+"garagesales",
            function(obj){
                obj=JSON.parse(obj);
                if(callback)
                    callback(obj);
            }
        );
    },
    remove:function(obj,callback){
        $.get(BASE_URL+"todo.php?axt=delete&data="+encodeURIComponent(obj.id),
            function(obj){
                $(document).trigger(obj.name + ":remove", obj.id);
                obj=JSON.parse(obj);
                if(callback)
                    callback(obj);
            }
        );
    }
}


Garagesale =  $.mvc.model.extend("garagesale",{
    validate:function(opts){
        if(opts&&opts.trigger)
            return "error validating";
        return true;
    },
    albumID: '',
    albumTitle: '',
    dateCreated: '',
    status: '',
    userID: '',
    firstName: '',
    lastName: '',
    email: '',
    avatar: '',
    username: '',
    images: []
}, myRemoteAdapter);

var garagesale = new Garagesale();